package hu.gar.web.login;

import hu.gar.vo.UserVO;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

@ManagedBean(name = "loggedInUser")
@SessionScoped()
public class LoggedInUser {

	private String username;

	@PostConstruct
	public void init() {
		HttpServletRequest request = (HttpServletRequest) FacesContext
				.getCurrentInstance().getExternalContext().getRequest();
		if (request.getUserPrincipal() != null) {
			setUsername(request.getUserPrincipal().getName());
		} else {
			setUsername(null);
		}

	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
}
